#!/bin/bash
#
# Packs Pulley into a temporary output file, extracts, and compares the
# results to the original source directory, to check for pack/unpack errors
#
# Author:   Dr. Mike Murphy (mmurphy2@coastal.edu)
# Revision: 11 November 2013
#
#   Copyright 2013 Coastal Carolina University
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#

[ -z "${PULLEY_TEST_TEMP}" ] && PULLEY_TEST_TEMP=/tmp

if [[ -z "${PULLEY_ROOT}" ]]; then
	myself=$(readlink -f "$0")
	whereami=$(dirname "${myself}")
	
	# Pulley root should be 2 directories up
	PULLEY_ROOT=$(dirname "${whereami}")
	PULLEY_ROOT=$(dirname "${PULLEY_ROOT}")
fi

if [[ -z "${PULLEY_TEST_HOME}" ]]; then
	# PULLEY_TEST_HOME should be PULLEY_ROOT/tests
	PULLEY_TEST_HOME="${PULLEY_ROOT}/tests"
fi

"${PULLEY_TEST_HOME}/components/pack_pulley"
"${PULLEY_TEST_HOME}/components/unpack_pulley"
diff -r "${PULLEY_ROOT}" "${PULLEY_TEST_TEMP}/pulley-test"
